package classes.view.component
{
	//한문제에 해당되는 노드
	public class QuizNode
	{
		
		private const OX_ALLOWED_DURATION :int = 5; //0X | 2지 푸는 시간  [초] 
		private const MULTI_ALLOWED_DURATION :int = 6; //4지 | 5지  퀴즈 푸는 시간  [초]
		
		private var _index : uint;
		private var _qs_no : int;
		private var _id : String; 
		private var _mode : String;
		private var _catagory : String; 
		private var _title : String;
		private var _isBig : Boolean;
		private var _answer: int;
		private var _userAnswer: int;
		
		//private var _isHard : Boolean; 
		private var _allowedTime : int;
		private var _img:String; 
		private var _translate :String; 
		private var _grade : int;
		private var _score : int; 
		private var _db : String;
		private var _choice1 : String; 
		private var _choice2 : String; 
		private var _choice3 : String; 
		private var _choice4 : String; 
		private var _choice5 : String; 
		
		
		
		//오답노트 관련 변수
		private var _percentage:int; 
		private var _isImportant: Boolean;
		private var _isQuizSaved : Boolean; 
		private var _source:String; //출처 
		private var _chapter:String;//단원
		private var _explaination :String;//설명
		private var _gqs_no :int
		
		
		
		private static const MAX_CHAR : Number = 800; 
		
		public function QuizNode($node:Object, $index :int)
		{
			this._index = $index; 
			
			if($node){
				
				this._choice1 = $node.no_1; 
				this._choice2 = $node.no_2;
				this._choice3 = $node.no_3;
				this._choice4 = $node.no_4;
				this._choice5 = $node.no_5;
				setMode();
				
				
				this._qs_no = $node.qs_no;
				this._catagory = $node.sb_name; 
				this._id = $node.question; 
				this._title = $node.question +"\n\n"+ $node.question_text;				
				this._img = $node.question_img; 
				this._answer = $node.answer; 
				this._translate = $node.translate; 
				this._explaination = $node.explain; 
				this._source = $node.origin;
				this._allowedTime = $node.time_limit; 
				this._grade = $node.grade;
				this._score = $node.score; 
				this._percentage = $node.rate; 
				this._chapter = $node.ch1_name + " > " + $node.ch2_name + " > " + $node.ch3_name;
				this._db = $node.db_name;
				this._isImportant = true;
				this._isQuizSaved = true;
				this._userAnswer = -1; //답변안한 상태
				
				
				
			}
			
		}
		
		
		private function setMode():void
		{
			if(this._choice3 == "" && (this._choice1 == "o" || this._choice1 == "O")) mode = "ox"; 
			else if(this._choice3 == "") mode = "m2";
			else if(this._choice5 == "") mode = "m4";
			else mode = "m5";
		}
		
		
		public function get isBig():Boolean
		{
			return _isBig;
		}
		
		
		public function get index():int
		{
			return _index;
		}
		
		public function get qs_no():int
		{
			return _qs_no;
		}
		
		
		public function get grade():int
		{
			return _grade;
		}
		
		
		public function set userAnswer($idx:int):void
		{
			this._userAnswer = $idx +1; 
		}
		
		public function get userAnswer():int
		{
			return this._userAnswer;
		}
		
		
		public function get id():String
		{
			return _id;
		}
		
		
		
		public function get catagory():String
		{
			return _catagory;
		}
		
		
		
		
		public function get title():String
		{
			return _title;
		}
		
		public function get choiceString() : String
		{
			var str : String = null; //ox 
			
			if(this._mode == "m2"){ //2지 선다 
				
				str = "1. " + this._choice1 + "\n\n" + 
					"2. " + this._choice2;
			}
			else if(this._mode == "m4"){ //4지 선다 
				
				str = "1. " + this._choice1 + "\n\n" + 
					"2. " + this._choice2 + "\n\n" +
					"3. " + this._choice3 + "\n\n" + 
					"4. " + this._choice4;
			}
			else if(this._mode == "m5")//5지 선다 
			{
				
				str = "1. " + this._choice1 + "\n\n" + 
					"2. " + this._choice2 + "\n\n" +
					"3. " + this._choice3 + "\n\n" + 
					"4. " + this._choice4 + "\n\n" + 
					"5. " + this._choice5;
			}
			
			return str;
		}
		
		public function get answer():int
		{
			return _answer;
		}
		
		
		public function get answerString():String
		{
			if(mode == "ox")
			{
				if(this._answer == 1) return "O";
				else return "X";
			}
			
			return answer.toString();
		}
		
		//
		public function set mode($str:String):void
		{
			
			this._mode = $str;
			
			if(this._mode == "m4" || this._mode == "m5")
			{
				_isBig = true; 
			}
			else
			{
				_isBig = false; 
			}
			
		}
		
		
		
		public function get mode():String
		{
			
			return this._mode;
		}
		
		
		public function get allowedTime():int
		{
			return _allowedTime;
		}
		
		public function get percentage():int
		{
			return _percentage;
		}
		
		public function set isImportant($bool:Boolean):void
		{
			this._isImportant = $bool;
		}
		
		
		public function get isImportant():Boolean
		{
			return _isImportant;
		}
		
		
		public function set isQuizSaved($bool:Boolean):void
		{
			this._isQuizSaved = $bool;
		}
		
		
		public function get isQuizSaved():Boolean
		{
			return this._isQuizSaved;
		}
		
		public function get state():int
		{
			if(isQuizSaved == false) return 0; 
			if(isImportant == true) return 2; 
			
			return 1;
		}
		
		
		public function get source():String
		{
			return _source;
		}
		
		public function get chapter():String
		{
			return _chapter;
		}
		
		
		
		public function get explaination():String
		{
			return _explaination;
		}
		
		
		public function set gqs_no($num:int):void
		{
			this._gqs_no = $num;
		}
		
		
		public function get gqs_no():int
		{
			return _gqs_no;
		}
		
		
	}
}